# -*- coding: utf-8 -*-
"""
检查数据库表是否存在的脚本
"""
from app.core.database import database
import pymysql

def check_table_exists():
    try:
        database.connect()
        cursor = database.execute_sql("SHOW TABLES LIKE 'sleep_analysis_sessions'")
        result = cursor.fetchall()
        
        # 检查 sleep_analysis_sessions 表是否存在
        
        print(f"sleep_analysis_sessions 表存在: {len(result) > 0}")
        
        if len(result) > 0:
            # 如果表存在，显示表结构
            cursor2 = database.execute_sql("DESCRIBE sleep_analysis_sessions")
            columns = cursor2.fetchall()
            print("\n表结构:")
            for col in columns:
                print(f"  {col[0]}: {col[1]}")
        
        database.close()
        
    except Exception as e:
        print(f"检查表失败: {e}")

if __name__ == "__main__":
    check_table_exists()